package commands;

import logic.UndoRedoManager;
import storage.Task;
import storage.TaskMemoryController;
import storage.TaskStatus;
import storage.UndoRedoDetails;

public class Complete {

	public String completeTask(int taskId) {
		Task task = TaskMemoryController.getTaskById(taskId);

		task.setStatus(TaskStatus.getByValue("Complete"));

		UndoRedoManager undoRedoManager = new UndoRedoManager();
		if (undoRedoManager.isNewCommand()) {
			UndoRedoDetails undoDetail_ = new UndoRedoDetails();
			undoDetail_
					.setDetails("complete", task.getId(), null, "status", "0", "1");
			undoRedoManager.storeChanges(undoDetail_);
		}

		Task completedTask = TaskMemoryController.setTask(task, taskId);
		return "Task " + completedTask.getTitle() + " completed.";
	}

}
